<?php
class Student {
private $surname;
private $first_name;

private $status;
private $emails;
private $grades;

  function __construct($surname, $first_name, $status)
  {
    $this ->surname = $surname;   
    $this ->first_name = $first_name;
    $this ->status = $status;
    $this ->emails = array();
    $this ->grades = array();
  }

  function add_email($which, $address)
  {
  $this->emails[$which] = $address;
  }
  function add_grade($grade)
  {
  $this->grades[] = $grade;
  }

  function average()
  {
  $total = 0;
  //grades = [34,56,89,16]
  foreach ($this->grades as $value)
  //$total += $value;
  $total = $total + $value;
  return $total / count($this->grades);
  }

  function toString()
  {
  $result = "";  
  $result = $this->first_name . ' ' . $this->surname;
  $result .= ' (' . $this->average() . ") $this->status \n";
  foreach ($this->emails as $which => $address)
  $result .= $which . ': ' . $address . "\n";
  $result .= "\n";
  return '<pre>' . $result . '</pre>';
  }
}